<template>
	<view class="level-type-container u-flex">
		<view class="l-box">
			<scroll-view scroll-y scroll-with-animation class="tab-list1" :show-scrollbar="false"
				:scroll-into-view="'item1-' + scrollItem1">
				<view v-for="(item, index) in list1" :key="index" class="tab-item1 u-flex-xy-center"
					:class="activeitem1 == index ? 'active' : ''" :id="'item1-' + index" @click="list1tap(index)">
					{{ item.fullName }}
				</view>
			</scroll-view>
		</view>
		<view class="r-box">
			<!-- <scroll-view
        scroll-x
        scroll-with-animation
        class="right-t-box"
        :show-scrollbar="false"
        :scroll-into-view="'item2-' + tabCur"
      >
        <view class="u-flex-y-center" style="width: auto; height: 100rpx">
          <u-tag
            v-for="(item, index) in list2"
            :key="index"
            :text="item.fullName"
            plain
            shape="circle"
            type="info"
            :bgColor="activeitem2 == index ? 'rgba(76,217,100,0.13)' : '#fff'"
            :borderColor="activeitem2 == index ? '#39C03E' : '#fff'"
            :color="activeitem2 == index ? '#39C03E' : '#333'"
            @click="list2tagTap(index)"
            :id="'item2-' + index"
          ></u-tag>
        </view>
      </scroll-view> -->
			<scroll-view :scroll-top="scrollTop" scroll-y class="right-b-box" :show-scrollbar="false" enhanced
				:refresher-enabled="activeitem1 != 0" refresher-background="#F4F4F4">
				<view v-for="(item2, index2) in list2" :key="index2" v-if="list3[index2].length != 0">
					<!-- <view class="tab-item2 u-flex-y-center">
            {{ item2.fullName }}
          </view> -->

					<u-divider :text="item2.fullName" textColor="#333"></u-divider>
					<view class="tab-box3">
						<view class="tab-item3 u-flex-xy-center" v-for="(item3, index3) in list3[index2]" :key="index3"
							@click="list3tagTap(list1[activeitem1], item2, item3)">
							<view class="u-line-2" style="text-align: center">
								{{ item3.fullName }}
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		getProductClassBuyerAndSeller,
		getProductClassAll
	} from "@/api/index.js";
	export default {
		props: {
			editfalg: {
				type: Boolean,
				default: false
			}
		},
		name: "type",
		data() {
			return {
				list: [],
				list1: [],
				activeitem1: 0,
				scrollItem1: 0,
				list2: [],
				activeitem2: 0,
				list3: [],
				scrollTop: 0,
			};
		},
		mounted() {
			this.init();
		},
		methods: {
			async init() {
				let res = await {};
				if (this.editfalg) {
					res = await getProductClassBuyerAndSeller();
				} else {
					res = await getProductClassAll();
				}
				this.list = res.data;
				this.list1 = this.list.filter((e) => {
					return e.parentId == 0;
				});
				if (this.list1.length != 0) {
					this.list1tap(0);
				}
			},
			list1tap(index) {
				if (index >= this.list1.length || index < 0) {
					return;
				}
				this.activeitem1 = index;
				this.list2 = this.list.filter((e) => {
					return e.parentId == this.list1[this.activeitem1].id;
				});
				this.list3 = this.list2.map((e) => {
					return this.list.filter((e2) => {
						return e2.parentId == e.id;
					});
				});
			},
			list3tagTap(item1, item2, item3) {

				this.$emit("click", {
					item1,
					item2,
					item3,
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.level-type-container {
		width: 100%;

		height: 100%;

		.l-box {
			width: 200rpx;
			height: 100%;
			background: #f5f5f5;

			.tab-list1 {
				height: 100%;

				.tab-item1 {
					height: 80rpx;
					font-size: 24rpx;

					&.active {
						background: #ffffff;
						color: #39c03e;
						border-left: 8rpx solid #39c03e;
					}
				}
			}
		}

		.r-box {
			width: 0;
			flex: 1;
			background: #ffffff;
			display: flex;
			flex-direction: column;

			.right-t-box {
				height: 100rpx;
				padding: 0 20rpx;
			}

			.right-b-box {
				flex: 1;
				height: 0;

				.tab-item2 {
					padding: 0 20rpx;
					font-size: 28rpx;
					height: 60rpx;
				}

				.tab-box3 {
					padding: 0 20rpx;
					display: flex;
					flex-wrap: wrap;
					justify-content: space-between;

					.tab-item3 {
						width: 160rpx;
						height: 80rpx;
						background: #f5f5f5;
						font-size: 24rpx;
						margin-bottom: 10rpx;
						border-radius: 10rpx;
						padding: 0 20rpx;
					}
				}
			}
		}
	}
</style>